package scene.grid
{
	import actor.Demon;
	import actor.Tower;
	import actor.event.TowerEvent;
	
	import flash.utils.Dictionary;

	public class GridVO
	{
		public var towerType:int;
		
		public var demonCount:int = 0;
		
		public var dictDemons:Dictionary =new Dictionary();
		public var dictTowerRange:Dictionary = new Dictionary();
		
		public function GridVO()
		{
		}
		
		public function setTower( t:Tower, isDelete:Boolean ):void
		{
			if( isDelete )
			{
				if( dictTowerRange[t] != null )
				{
					delete dictTowerRange[t];
				}
			}
			else
			{
				dictTowerRange[t] = t;
			}
		}
		
		public function setDemon( v:Demon, isDelete:Boolean ):void
		{
			if( !isDelete )
			{
				demonCount++;
				dictDemons[v] = v;
				for( var i:* in dictTowerRange )
				{
					var t:Tower = (i as Tower); 
					t.dispatchEvent( new TowerEvent( TowerEvent.ATTACK_ME, v ) );
				}
			}
			else
			{
				//有可能多个demon占用一个格子
				demonCount--;
				if( demonCount <= 0 )
				{
					demonCount = 0;
				}
				if( dictDemons[v] != null )
				{
					delete dictDemons[v];
				}
			}
		}
	}
}















